#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <strstream>
#include <stdio.h>

using namespace std;

void get_stampcombination(int* value, int n, int r );

int main(){
    int value[255];
    int n = 0;
    value[n++] = 0;
    char tmpstr[255];
    cin.getline(tmpstr, 255);
    while(strlen(tmpstr)){
        istrstream in1(tmpstr);
        int stype;
        in1 >> stype;
        while(stype != 0){
            value[n++] = stype; 
            in1 >> stype;
        }
        cin.getline(tmpstr, 255);
        istrstream in2(tmpstr);
        int r;
        in2 >> r;
        while(r != 0){
 		get_stampcombination(value, n, r);
       		in2 >> r;
        }
        cin.getline(tmpstr, 255);
        n = 0;
        value[n++] = 0;
    }
    return 0;
}


void get_stampcombination(int* value, int n, int r){
 //	printf("n is %d r is %d\n", n, r);
	int maxstamptype = -1;
	int minstampnum = 100;
	int maxhighestvalue = -1;
	bool tie = false;
	int curstamptype;
	int curstampnum;
	int curhighestvalue;
	int s[4];
	int fs[4];
	for(s[0] = 0; s[0] < n; s[0]++){
		for(s[1] = s[0]; s[1] < n; s[1]++){
			for(s[2] = s[1]; s[2] < n; s[2]++){
				for(s[3] = s[2]; s[3] < n; s[3]++){
					if(value[s[0]] + value[s[1]] + value[s[2]] + value[s[3]] != r) continue;
					curstamptype = 0;
					curstampnum = 0;
					curhighestvalue = -1;
					if(s[0]){curstampnum++; curstamptype++; if(value[s[0]]>curhighestvalue) {curhighestvalue=value[s[0]];} }
					if(s[1]){curstampnum++; if(s[1] != s[0]){curstamptype++;} if(value[s[1]]>curhighestvalue) {curhighestvalue=value[s[1]];} }
					if(s[2]){curstampnum++; if(s[2] != s[1]){curstamptype++;} if(value[s[2]]>curhighestvalue) {curhighestvalue=value[s[2]];} }
					if(s[3]){curstampnum++; if(s[3] != s[2]){curstamptype++;} if(value[s[3]]>curhighestvalue) {curhighestvalue=value[s[3]];} }
					if(curstamptype < maxstamptype) continue;
					if(curstamptype > maxstamptype){
						maxstamptype = curstamptype;
						minstampnum = curstampnum;
						maxhighestvalue = curhighestvalue;
						tie =false;
						fs[0]=s[0]; fs[1]=s[1]; fs[2]=s[2]; fs[3]=s[3];
						continue;
					}
					if(curstampnum > minstampnum ) continue;
					if(curstampnum < minstampnum){
						minstampnum = curstampnum;
						maxhighestvalue = curhighestvalue;
						tie = false;
						fs[0]=s[0]; fs[1]=s[1]; fs[2]=s[2]; fs[3]=s[3];
						continue;
					}
					if(curhighestvalue < maxhighestvalue) continue;
					if(curhighestvalue > maxhighestvalue){
						maxhighestvalue = curhighestvalue;
						tie = false;
						fs[0]=s[0]; fs[1]=s[1]; fs[2]=s[2]; fs[3]=s[3];
						continue;
					}
					tie = true;
				}
			}
		} 
	}
	if(maxstamptype == -1){
		 cout<<r<<" ---- none"<<endl;
     return;
	}
	cout << r << " (" << maxstamptype << "):";
	if(tie){
		cout << " tie" <<endl;
		return;
	}
	for(int i = 0; i < 4; i++){
		if(fs[i]){
			cout << " " << value[fs[i]];
		} 
	}
	cout << endl;
}

